<%@include file="aaa.jsp"%>

<%
	String userQuery = "select from " + Users.class.getName() + " where email!='"+ user.getEmail() +"'";
    List<Users> users = (List<Users>) pm.newQuery(userQuery).execute();
    String query = "select from " + Item.class.getName() + " where owner=='"+ user.getEmail() +"'";
    List<Item> items = (List<Item>) pm.newQuery(query).execute();
    
	if (items.isEmpty()) {
%>
		<p>Your db has no items.</p>
<%
    } else {
%>

				<table class='list'>
<%
		int alternate = 0;
        for (Item i : items) {
			++alternate;
%>
					<tr class='<% if(alternate%2==0){%>item-odd<%}else{%>item-pair<%}%>'
						onmouseover='this.className="item-over";'
						onmouseout='this.className="<% if(alternate%2==0){%>item-odd<%}else{%>item-pair<%}%>";'>
						<td class='item-title'>
							<%= i.getTitle() %>
						</td>
						<td class='item-ico'>
							<img class='ico' src='
							<% if (i.getType().equals("DVD")) {%>
							img/dvd.png
							<%} else if(i.getType().equals("CD")) {%>
							img/cd.png
							<%} else if(i.getType().equals("Book")) {%>
							img/book.png
							<%}%>
							' />
						</td>
						<td class='item-type'>
							<%= i.getType() %>
						</td>
						<td class='item-lend'>
<%
						if (i.isReserved() ){
%>
						<span style='font-size:12px; color:red; font-weight:bold;'>Lent to </span>
						<span style='font-size:13px; color:#AAAAAA; font-weight:bold; margin-left:20px;'><%=i.getBorrower() %></span>
<%
							 } 
							 else {
%>
						       <form action="/lendItem" method="post" >
							    	<input type="hidden" value="<%= i.getItemID().getId() %>" name="itemID" />
							        <select class='friend' name="person">
							        		<% for (Users u : users){%>
							    			   <option> <%= u.getEmail() %> </option>
							                <% }%>
							    		  </select>
							        <input class='lend' type="submit" value="Lend to" />
						       </form>
<%
						      }
%>
						</td>
						<td class='item-return'>
						   	   <form action="/deleteItem" method="post" >
							    	<input type="hidden" value="<%= i.getItemID().getId() %>" name="itemID" />
							        <input type="hidden" value="<%= user.getEmail() %>" name="person" />
							        <input class='return' type="submit" value="Return" <% if(!i.isReserved()){ %> disabled="disabled" <% } %>/>
						       </form>
						</td>
					</tr>
<%
        }
%>
				</table>


<%
    }
%>